home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13328 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: vixen.cso.uiuc.edu!usenet
  2. From: Dragos-Anton Manolescu <manolesc@uiuc.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Q: throwing exceptions in constructors
  5. Date: 24 Mar 1996 19:51:11 -0600
  6. Organization: University of Illinois at Urbana-Champaign
  7. Message-ID: <opu3ze7xf4.fsf@sweetbay.will.uiuc.edu>
  8. Reply-To: Dragos Manolescu <manolesc@uiuc.edu>
  9. NNTP-Posting-Host: sweetbay.will.uiuc.edu
  10. X-Newsreader: Gnus v5.1
  11.  
  12.  
  13. Hi,
  14.  
  15. I was wondering if it's possible to throw an exception from within a
  16. constructor (a word of caution: this is my first attempt to use
  17. exceptions :-) Suppose the constructor calls new and this fails. Then
  18. I would like to throw an exception to inform the calling program that
  19. an abnormal situation occured. Is this possible? I tried something
  20. like:
  21.  
  22. ...
  23. MyClass myObject(1,2,3)
  24. ...
  25.  
  26. inside a try statement but the compiler complained (I use g++ 2.7.2,
  27. BTW). Am I doing something wrong? What would be an elegant way to
  28. handle this?
  29.  
  30. I would appreciate an e-mail reply, if possible. Thanx in advance for
  31. your time,
  32. -- 
  33. dam                                    http://www.uiuc.edu/ph/www/manolesc
  34.